//https://leetcode.cn/problems/subsets/
package codeRandomThoughts.Test78子集;

import java.util.ArrayList;
import java.util.List;

public class Solution2 {
    List<Integer> path = new ArrayList<>();
    List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        backtracking(nums, 0);
        return result;
    }

    public void backtracking(int[] nums, int startIndex) {
        if (path.size() <= nums.length) {
            result.add(new ArrayList<>(path));
        } else {
            return;
        }

        //单层递归逻辑
        for (int i = startIndex; i < nums.length; i++) {
            path.add(nums[i]);
            backtracking(nums, i + 1);
            path.remove(path.size() - 1);
        }
    }
}
